<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 							  xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
            doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>  
    <xsl:template name="days_loop">
        <xsl:param name="day_iterator" select="1"/>
        <xsl:param name="days"/>
        <xsl:param name="starting_hour"/>
        <xsl:param name="starting_hour_2" select="$starting_hour"/>
        <xsl:if test="$day_iterator &lt; $days">
            <td>
            	<b><xsl:value-of select="//course[session[(@day = $day_iterator ) and (@start &lt;= $starting_hour ) and (@end &gt; $starting_hour_2 )]]/@course_name"/></b><br/>
            	<xsl:value-of select="//course[session[(@day = $day_iterator ) and (@start &lt;= $starting_hour ) and (@end &gt; $starting_hour_2 )]]/@course_group"/>
            </td>
            <xsl:call-template name="days_loop">
                <xsl:with-param name="day_iterator" select="$day_iterator + 1"/>
                    <xsl:with-param name="days" select="$days"/>
                    <xsl:with-param name="starting_hour" select="$starting_hour"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    <xsl:template name="hours_loop">
        <xsl:param name="hour" select="8"/>
        <xsl:param name="hours"/>
        <xsl:if test="$hour &lt; $hours">
            <tr>
                <td>
                    <xsl:value-of select="concat($hour,':00')"/>
                </td>
                <xsl:call-template name="days_loop">
                    <xsl:with-param name="days" select="8"/>
                    <xsl:with-param name="starting_hour" select="$hour"/>
                </xsl:call-template>
            </tr>
            <xsl:call-template name="hours_loop">
                <xsl:with-param name="hour" select="$hour + 1"/>
                <xsl:with-param name="hours" select="$hours"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    <xsl:template match="/">
    <link rel="stylesheet" type="text/css" href="css/stylesheet_1.css"/>
	<b><i>Here's your timetable...</i></b><br/><br/>
	<b>legend:</b><table class='imagetable'><tr><td>Course name<br/>Course group</td></tr></table><br/><br/>   
	    <table class='imagetable'>
	        <thead>
	            <tr>
	                <th></th>
	                <th>Sunday</th>
	                <th>Monday</th>
	                <th>Tuesday</th>
	                <th>Wednesday</th>
	                <th>Thursday</th>
	                <th>Friday</th>
	                <th>Saturday</th>
	            </tr>
	        </thead>
	        <tbody>
	            <xsl:call-template name="hours_loop">
	                <xsl:with-param name="hours" select="18"/>
	            </xsl:call-template>
	        </tbody>
	    </table>
	    </xsl:template>
</xsl:stylesheet>